package sartoservicesync.utils;

import java.io.File;
import java.io.IOException;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.SchemaOutputResolver;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;

import sartoservicesync.entities.presta.PrestaCustomer;
import sartoservicesync.entities.presta.PrestaProduct;

/**
 * Generiert XSDs aus Java-Klassen
 * @author waldemar.lammert
 *
 */
public class XSDGenerator {

	public static void main(String[] args) {

		try {
			String current = new java.io.File(".").getCanonicalPath();
			final File folder = new File(current + "/schemas");
			if (folder.exists()) {
				folder.delete();
			}
			folder.mkdir();
			class MySchemaOutputResolver extends SchemaOutputResolver {
				public Result createOutput(String namespaceUri,
						String suggestedFileName) throws IOException {
					return new StreamResult(new File(folder, suggestedFileName));
				}
			}
			JAXBContext context;
			context = JAXBContext.newInstance(PrestaProduct.class,
					PrestaCustomer.class);
			context.generateSchema(new MySchemaOutputResolver());
			System.out.println("Klassen wurden erfolgreich in diesem Ordner generiert: "+folder);
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}

}
